package com.pms.controller;

import com.pms.dto.BuildingPageQueryDTO;
import com.pms.dto.BuildingSaveDTO;
import com.pms.dto.BuildingUpdateDTO;
import com.pms.entity.Building;
import com.pms.result.PageResult;
import com.pms.result.Result;
import com.pms.service.BuildingService;
import com.pms.vo.BuildingSelectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 楼栋相关接口
 */
@Api(tags = "楼栋相关接口")
@RestController
@RequestMapping("/building")
@Slf4j
public class BuildingController {

    @Autowired
    private BuildingService buildingService;

    /**
     * 新增楼栋
     * @param buildingSaveDTO
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新增楼栋")
    public Result<String> save(@RequestBody BuildingSaveDTO buildingSaveDTO){
        log.info("新增楼栋:{}",buildingSaveDTO);
        buildingService.save(buildingSaveDTO);
        return Result.success();
    }

    /**
     * 楼栋分页查询
     * @param buildingPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("楼栋分页查询")
    public Result<PageResult> page(BuildingPageQueryDTO buildingPageQueryDTO){
        log.info("楼栋分页查询:{}",buildingPageQueryDTO);
        PageResult pageResult=buildingService.pageQuery(buildingPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("根据id批量删除")
    public Result<String> delete(@RequestParam List<Integer> ids){
        log.info("根据id批量删除,{}",ids);
        buildingService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改楼栋信息
     * @param buildingUpdateDTO
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改楼栋信息")
    public Result<String> update(@RequestBody BuildingUpdateDTO buildingUpdateDTO){
        log.info("修改楼栋信息,{}",buildingUpdateDTO);
        buildingService.update(buildingUpdateDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("根据小区id获取楼栋列表")
    public Result<List<BuildingSelectVO>> list(Integer communityId){
        log.info("根据小区id获取楼栋列表,{}",communityId);
        List<BuildingSelectVO> list=buildingService.list(communityId);
        return Result.success(list);
    }
}
